package com.zebra.gateway.protocol;

import com.zebra.common.ZebraBaseMessage;
import com.zebra.remoting.config.StateMessage;
import com.zebra.remoting.connection.Connection;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;

public class GatewaySendMessageUtil {

    public static void sendStateMessage(ChannelHandlerContext ctx, GatewayCommand msg, int stateCode){
        msg.setState(stateCode);
        msg.setMessage(StateMessage.builder().state(stateCode).build());
        msg.messageEncoder();
        ctx.writeAndFlush(msg);
    }
    public static void sendMessage(Channel ctx, GatewayCommand msg){
        msg.messageEncoder();
        ctx.writeAndFlush(msg);
    }

    public static void sendMessage(Channel channel, int cmd, ZebraBaseMessage message){
        GatewayCommand command = new GatewayCommand();
        command.setCmd(cmd);
        command.setMessage(message);
        command.messageEncoder();
        channel.writeAndFlush(command);
    }

    public static void sendMessage(Connection connection, GatewayCommand command){
        command.messageEncoder();
        connection.writeAndFlush(command);
    }
}
